package com.xyz.service;

import com.xyz.dao.logic.SLotteryLogic;
import com.xyz.domain.constants.EhCacheConstants;
import com.xyz.domain.table.SLottery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LotteryInfoService extends BaseService{

    @Autowired
    SLotteryLogic lotteryLogic;

    @Cacheable(cacheNames = EhCacheConstants.LotteryInfoCache,key = "#key")
    public SLottery getLotteryInfo(String key){
        SLottery lotteryInfo = getAllLotteryInfos().stream().filter(x->{
            return x.getCode().equals(key);
        }).findFirst().orElse(null);
        return lotteryInfo;
    }

    @Cacheable(cacheNames = EhCacheConstants.LotteryInfoCache)
    public List<SLottery> getAllLotteryInfos(){
        return lotteryLogic.getAllLotteryInfos();
    }

    @CacheEvict(cacheNames = EhCacheConstants.LotteryInfoCache,allEntries=true)
    public void doRefresh(){

    }

}
